package org.dtrd.modules.record.entity.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.common.util.DateUtils;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.record.constant.RecordConstant.InsulinInjection;
import org.dtrd.modules.record.entity.po.DtrdEntRdSigninInsulin;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @Author: QR
 * @Date: 2021/10/17-23:13
 */
@ApiModel("胰岛素记录对象")
@Data
public class InsulinRecordBean {

    @ApiModelProperty("记录id")
    private Integer dataId;

    @NotNull
    @ApiModelProperty("患者id")
    private Integer patientId;

    @NotBlank
    @ApiModelProperty("记录时间")
    private String recordTime;

    @ApiModelProperty("记录照片")
    private String recordPhoto;

    /**
     * {@link Constant.InsulinRecordType}
     */
    @NotNull
    @Range(min = 1, max = 5)
    @ApiModelProperty(value = "注射时项", notes = "1-早,2-午,3-晚,4-睡前 胰岛素泵（CSII）- 5")
    private Integer insulinType;

    /**
     * {@link InsulinInjection}
     */
    @ApiModelProperty(value = "注射情况", notes = "1-遵嘱注射 2-漏注射 3-自停打")
    @NotNull
    @Range(min = 1, max = 3)
    private Integer injection;

    @ApiModelProperty("胰岛素用量")
    private String insulinDescribe;

    @ApiModelProperty("备注")
    private String insulinRemark;

    public InsulinRecordBean() {
    }

    public InsulinRecordBean(Integer patientId, Date date, Constant.InsulinRecordType type, String desc) {
        this.patientId = patientId;
        this.recordTime = DateUtils.formatDate(date, DateUtils.datetimeFormat.get().toPattern());
        this.insulinType = type.getType();
        this.insulinDescribe = desc;
    }

    public InsulinRecordBean parseFromPo(DtrdEntRdSigninInsulin po) {
        this.setDataId(po.getDataId());
        this.setPatientId(po.getPatientId());
        this.setInsulinRemark(po.getInsulinRemark());
        this.setInsulinDescribe(po.getInsulinDescribe());
        if (po.getRecordDate() != null) {
            this.setRecordTime(DateUtils.formatTime(po.getRecordTime()));
        }
        this.setRecordPhoto(po.getRecordPhoto());
        this.setInsulinType(po.getInsulinType());
        injection = po.getInsulinInjection();
        return this;
    }
}
